/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：FeedbackDialog.java <br>
 * 创建时间：2015-4-11 下午8:27:07 <br>
 * 所属项目：GmudEX <br>
 *
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui.meta;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.BmobObject;
import cn.bmob.v3.listener.SaveListener;
import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.R;

/**
 * 类名：FeedbackDialog <br>
 * 说明：找朋友
 *
 * @author 12548
 */
public class FeedbackDialog extends Dialog {

	private Window mWindow;

	EditText et1, et2;


	/**
	 * @param context
	 */
	public FeedbackDialog(Context context) {
		super(context);
		mWindow = getWindow();
		mWindow.setBackgroundDrawable(new ColorDrawable(0));
		mWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
		WindowManager.LayoutParams lp = mWindow.getAttributes();
		lp.gravity = Gravity.CENTER;
		lp.dimAmount = 0.0001f;
		mWindow.setAttributes(lp);
		setCanceledOnTouchOutside(true);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		mWindow.setContentView(R.layout.dialog_feedback);

		et1 = (EditText) findViewById(R.id.etResetEmail);
		et2 = (EditText) findViewById(R.id.editText2);
		Button btn = (Button) findViewById(R.id.btnResetPassword);
		btn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				String content = et2.getText().toString();

				if (content.trim().isEmpty()) {
					Toast.makeText(Game.getInstance(), "内容不能为空！", Toast.LENGTH_SHORT).show();
					return;
				}


				GmudFeedback gfb = new GmudFeedback(et1.getText().toString(), content);
				Toast.makeText(Game.getInstance(), "正在提交，请稍候。。。", Toast.LENGTH_SHORT).show();
				gfb.save(Game.getInstance(), new SaveListener() {

					@Override
					public void onFailure(int arg0, String arg1) {
						Toast.makeText(Game.getInstance(), "反馈提交失败！", Toast.LENGTH_SHORT).show();
					}

					@Override
					public void onSuccess() {
						Toast.makeText(Game.getInstance(), "反馈提交成功，感谢您的支持！", Toast.LENGTH_SHORT).show();
						FeedbackDialog.this.dismiss();
						Game.getInstance().popToRootScreen();
					}

				});

			}

		});

	}

	public static final class GmudFeedback extends BmobObject {

		private static final long serialVersionUID = 3263135706327399642L;

		/**
		 * @param name
		 * @param content
		 */
		public GmudFeedback(String name, String content) {
			super();
			this.name = name;
			this.content = content;
		}

		private String name;
		private String content;

		/**
		 * @return name
		 */
		String getName() {
			return name;
		}

		/**
		 * @param name 要设置的 name
		 */
		void setName(String name) {
			this.name = name;
		}

		/**
		 * @return content
		 */
		String getContent() {
			return content;
		}

		/**
		 * @param content 要设置的 content
		 */
		void setContent(String content) {
			this.content = content;
		}
	}
}
